<template>
  <div>
   <ul class="mui-table-view">
    <li class="mui-table-view-cell mui-media" v-for="items in newslist" :key="items.id">
      <router-link :to="'newlist/' + items.id">
        <img class="mui-media-object mui-pull-left" :src="items.img">
        <div class="mui-media-body" style="text-align: left;">
          <h4>{{items.title}}</h4>
          <p class='mui-ellipsis' style="display: flex;">
             <span>{{items.time}}前发布</span>
             <span>点赞：{{items.num}}次</span>
          </p>
        </div>
      </router-link>
    </li>
  </ul>
  </div>
</template>

<script>
export default {
  data () {
    return {
      newslist: []
    }
  },
  created () {
    this.getnews()
  },
  methods: {
    getnews () {
      this.axios.get('newslist.json').then(
        rs => {
          this.newslist = rs.data
          // 格式化发布时间，点赞数
          for (var i = 0; i < this.newslist.length; i++) {
            // 点赞数式化
            if (this.newslist[i].num >= 1000) {
              if (this.newslist[i].num >= 10000) {
                this.newslist[i].num = parseInt(this.newslist[i].num / 10000) + '万'
              } else {
                this.newslist[i].num = parseInt(this.newslist[i].num / 1000) + '千'
              }
            }
            // 发布时间格式化
            if (this.newslist[i].time >= 60) {
              this.newslist[i].time = parseInt(this.newslist[i].time / 60) + '小时'
            } else {
              this.newslist[i].time += '分钟'
            }
          }
        },
        err => {
          console.log('请求失败：' + err)
        })
      console.log('ssa' + this.num)
    }
  }
}
</script>

<style lang="scss" scoped>
.mui-table-view{
  margin: auto;
  width: 99vw;
  h4{
    font-size: 14px;
    color: #334;
  }
  .mui-ellipsis{
    display: flex;
    justify-content: space-between;
  }
  span{
    display: inline-block;
    width: 90px;
    text-align: left;
    font-size: 12px;
    color: #09e;
  }
}
</style>
